from contextlib import asynccontextmanager
from typing import AsyncGenerator
import config
from core.init_model import init_asr_pipeline
from fastapi import FastAPI


@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
    """
    FastAPI lifespan manager to initialize and cleanup resources
    """
    
    # 初始化ASR pipeline
    print("Initializing ASR pipeline...")
    asr_pipeline = init_asr_pipeline(device="cuda:0")
    config.ASR_PIPELINE = asr_pipeline
    print("ASR pipeline initialized successfully!")
    
    yield




